//
// Created by Huafv on 2024/10/11.
//

#ifndef BT_PHY_BUS_IF_H4_H
#define BT_PHY_BUS_IF_H4_H

#include <stdint.h>
#include "bt_common.h"


#define PHYBUSIF_PACKET_TYPE_CMD         0x01
#define PHYBUSIF_PACKET_TYPE_ACL_DATA    0x02
#define PHYBUSIF_PACKET_TYPE_SCO_DATA    0x03
#define PHYBUSIF_PACKET_TYPE_EVT         0x04
#define PHYBUSIF_PACKET_TYPE_ISO         0x05

enum phybusif_state
{
    W4_PACKET_TYPE,
    W4_EVENT_HDR,
    W4_ACL_HDR,
    W4_SCO_HDR,
    W4_EVENT_PARAM,
    W4_ACL_DATA,
    W4_SCO_DATA,
};

struct phybusif_cb
{
    int phyuart_fd;
    enum phybusif_state state;
    struct bt_pbuf_t *p;
    hci_evt_hdr_t *evhdr;
    hci_acl_hdr_t *aclhdr;
};


void phybusif_open(uint32_t baud_rate);
err_t phybusif_input(struct phybusif_cb *cb);

void uart_bt_send(uint8_t *buf, uint16_t len);

#endif //BT_PHY_BUS_IF_H4_H
